package reviewQueue;

import java.util.ArrayDeque;
import java.util.Stack;

public class StackQueue {
    public ArrayDeque<Integer> s1;
    public  ArrayDeque<Integer> s2;
    public StackQueue(){
        s1=new ArrayDeque<>();
        s2=new ArrayDeque<>();
    }
    //入队
    public void offer(int val){
            s1.push(val);
        System.out.println(val+"入队成功！");
    }
    //判两栈空
    public boolean empty(){
        return s1.isEmpty()&&s2.isEmpty();
    }
    //出队
    public void poll(){
        if(empty()){
            System.out.println("两栈为空！");
            return;
        }

        if(s2.isEmpty()||s1.isEmpty()){
            while(!s1.isEmpty()){
                s2.push(s1.pop());
            }
            System.out.println("出队元素为："+s2.pop());
        }
    }
    //获取队头元素
    public void peek(){
        if(empty()){
            System.out.println("队为空！");
        }
        if(s2.isEmpty()||s1.isEmpty()){
            while(!s1.isEmpty()){
                s2.push(s1.pop());
            }
            System.out.println("队头元素为"+s2.peek());
        }

    }
}
